package zunge.lbe.analysis;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class ScriptMgr {
	
	public static void splitScript(List<String> scripts, int coreCount, String fileName) throws Exception{
		BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));

		int size = ((scripts.size()-1) / (coreCount))+1;
		
		for(int i = 0;i < coreCount;++i){
			String fileNamei = fileName+"."+i+".sh";
			BufferedWriter bwi = new BufferedWriter(new FileWriter(fileNamei));
			for(int j = i*size;j < Math.min((i+1)*size, scripts.size());++j){
				if(j < scripts.size()){
					bwi.write(scripts.get(j)+"\n");
				}
			}
			bwi.close();
			bw.write("sh "+fileNamei+" &\n");
		}
		bw.close();
	}
	
}
